import Loading from '@/components/loading/index'
import NotFound from 'bundle-loader?lazy&name=notFound!@/view/NotFound/index'
import Page1 from 'bundle-loader?lazy&name=page1!@/view/Page1/index'
import Page2 from 'bundle-loader?lazy&name=page2!@/view/Page2/index'
import Page3 from 'bundle-loader?lazy&name=page3!@/view/Page3/index'
import Page4 from 'bundle-loader?lazy&name=page4!@/view/Page4/index'
import React from 'react'
import { Route, Switch } from 'react-router-dom'
import Bundle from './bundle'

const createComponent = component => props => <Bundle load={component}>{Component => (Component ? <Component {...props} /> : <Loading />)}</Bundle>

export default () => (
    <div>
        <Switch>
            <Route exact path='/' component={createComponent(Page1)} />
            <Route path='/page2' component={createComponent(Page2)} />
            <Route path='/page3' component={createComponent(Page3)} />
            <Route path='/page4' component={createComponent(Page4)} />
            <Route component={createComponent(NotFound)} />
        </Switch>
    </div>
)
